<?php

require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
include('connect_db.php');

// $act = $_GET[act];
// $date = $_GET[date];

class MYPDF extends TCPDF {

	//Page header
	public function Header() {

		// Title
		$ypage=10;
		$this->SetFont('helvetica', 'B', 12);
		$this->MultiCell('', 5, 'Lembongan Island - Bali', 0, 'L', 0, 0, '', $ypage, true); 
		$this->SetFont('helvetica', '', 10);
		$this->MultiCell('', 5, 'purinusa@hotmail.com +62 366 559 63 72', 0, 'L', 0, 0, '', $ypage+6, true);
		$style3 = array('width' => 0.3, 'cap' => 'round', 'join' => 'round', 'dash' => 0, 'color' => array(0, 0, 0));
		$this->Line(15, $ypage+14, 281, $ypage+14, $style3);
		$this->Line(15, $ypage+15, 281, $ypage+15, $style3);

		// Keterangan laporan
		$this->SetFont('helvetica', 'B', 10);
		$ypage2=28;

		if ($_GET[act] == "monthviewrestaurant") {
			$sub_head = "Month Restaurant Sale Report";
			$exdate = explode("-",$_GET[date]);
			$month_name = array("January", "February", "March", "April", "Mei", "June", "July", "August", "September", "October", "November", "December");
			$month = $exdate[1];
			$display_date = $month_name[$month-1].", ".$exdate[0];
		}elseif ($_GET[act] == "yearviewrestaurant") {
			$sub_head = "Year Restaurant Sale Report";
			$display_date = $_GET[date];
		}
		
		$this->MultiCell('', 5, $sub_head.' in '.$display_date, 0, 'L', 0, 0, '', $ypage2, true);
		$this->SetFont('helvetica', '', 10);
	}

	// Page footer
	public function Footer() {

		$style3 = array('width' => 0.5, 'cap' => 'round', 'join' => 'round', 'dash' => 0, 'color' => array(0, 0, 0));
		$this->Line(10, 285, 200, 285, $style3);
		// Position at 10 mm from bottom
		$this->SetY(-10);
		// Set font
		$this->SetFont('helvetica', 'I', 8);
		// Page number
		$this->Cell(0, 7, 'Page '.$this->getAliasNumPage().' of '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
		$style = array(
			'position' => '',
			'align' => 'L',
			'stretch' => false,
			'fitwidth' => false,
			'cellfitalign' => '',
			'border' => false,
			'hpadding' => '',
			'vpadding' => '',
			'fgcolor' => array(0,0,0),
			'bgcolor' => false, //array(255,255,255),
			'text' => true,
			'font' => 'helvetica',
			'fontsize' => 6,
			'stretchtext' => 0
		);
	}
}

// create new PDF document
$pdf = new MYPDF('L', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Lembongan Island');
$pdf->SetTitle('Report');
$pdf->SetSubject('Room Report');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set font
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(false, PDF_MARGIN_BOTTOM);
$pdf->SetFont('helvetica', '', 12);

$pdf->AddPage();

$ypage2=8;

$pdf->SetFont('helvetica', '', 9);

	if ($_GET[act] == "monthviewrestaurant") {

		$html = '
			<table border="1" cellpadding="3">
				<thead>
			    <tr>
			      <td style="vertical-align: middle; text-align: center; width:30px;">No.</td>
			      <td style="vertical-align: middle; text-align: center; width:300px;">Menu Name</td>
			      <td style="vertical-align: middle; text-align: center; width:154px;">Price (IDR)</td>
			      <td style="vertical-align: middle; text-align: center; width:100px;">Quantity</td>
			      <td style="vertical-align: middle; text-align: center; width:170px;">Amount (IDR)</td>
			    </tr>
			  </thead>

			  <tbody>';
					$grand_total = 0;
	      	$hitungBaris = 0;
					$sql_year = "SELECT id AS id_resto_real, tanggal, MONTH(tanggal) AS month_select, DATE_FORMAT(tanggal, '%d') AS date_select, 
					DATE_FORMAT(tanggal, '%M %d, %Y') AS resto_date FROM resto 
					WHERE CONCAT(YEAR(tanggal),'-',MONTH(tanggal)) = '".$_GET[date]."' 
					AND id IN (SELECT idresto FROM nota WHERE is_paid = 1 AND is_service_charge = 0) 
					AND id IN (SELECT idresto FROM resto_menu)
					GROUP BY DATE_FORMAT(tanggal, '%d') ASC";
					// echo $sql_year;
					$query_year = mysql_query($sql_year);
					$count_year = mysql_num_rows($query_year);
					if ($count_year > 0) {
						$urut_menu = 1;
						$query_year = mysql_query($sql_year);
						while ($baris_year = mysql_fetch_array($query_year)) {
							$sql_month = "SELECT id AS id_resto_real, tanggal, MONTH(tanggal) AS month_select, DATE_FORMAT(tanggal, '%d') AS date_select, 
							DATE_FORMAT(tanggal, '%M %d, %Y') AS resto_date FROM resto 
							WHERE CONCAT(YEAR(tanggal),'-',MONTH(tanggal)) = '".$_GET[date]."' AND DATE_FORMAT(tanggal, '%d') = '".$baris_year[date_select]."'
							AND id IN (SELECT idresto FROM nota WHERE is_paid = 1 AND is_service_charge = 0) 
							AND id IN (SELECT idresto FROM resto_menu)
							ORDER BY DATE_FORMAT(tanggal, '%d') ASC";
							$query_month = mysql_query($sql_month);
							$count_month = mysql_num_rows($query_month);
							if ($count_month > 0) {
								$html=$html.'
								<tr>
									<td colspan="5" style="background-color: #ccc; font-weight:bold;">'.$baris_year[resto_date].'</td>
								</tr>
								';
								$sql_list_item = "SELECT * FROM resto_menu a
								WHERE a.idresto IN (SELECT id FROM resto WHERE CONCAT(YEAR(tanggal),'-',MONTH(tanggal)) = '".$_GET[date]."' 
								AND DATE_FORMAT(tanggal, '%d') = '".$baris_year[date_select]."') GROUP BY a.idmenu ASC";
								$query_list_item = mysql_query($sql_list_item);
								$count_list_item = mysql_num_rows($query_list_item);
								if ($count_list_item > 0) {
									$query_cek_item = mysql_query($sql_list_item);
									while ($baris_cek_item = mysql_fetch_array($query_list_item)) {
										$sql_cek_per_item = "SELECT b.id AS id_menu, b.nama AS nama_menu, 
										a.harga_ori AS harga_menu, a.harga AS harga_jual FROM resto_menu a
										LEFT JOIN menu b ON b.id = a.idmenu
										WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.idresto IN 
										(SELECT id FROM resto WHERE CONCAT(YEAR(tanggal),'-',MONTH(tanggal)) = '".$_GET[date]."' 
										AND DATE_FORMAT(tanggal, '%d') = '".$baris_year[date_select]."') GROUP BY a.harga";
										$query_cek_per_item = mysql_query($sql_cek_per_item);
										$hasil_cek_item = 0;
										$hasil_all_item = 0;
										while ($baris_cek_per_item = mysql_fetch_array($query_cek_per_item)) {
											$hasil_all_item++;
											if ($baris_cek_per_item['harga_menu'] != $baris_cek_per_item['harga_jual']) {
												$hasil_cek_item++;
											}
										}

										if ($hasil_cek_item == 0) {
			        				$hitungBaris++;
										}else{
			        				$hitungBaris += ($hasil_all_item+1);
										}

										$temBaris = $hasil_all_item+1;

										if($hitungBaris >= 24){
											$html = $html.'</tbody></table>';
											$pdf->writeHTMLCell(0, 0, '14', $ypage2+28, $html, 0, 1, 0, true, 'L', true);
											$pdf->AddPage();
											$hitungBaris = $temBaris;
											$html = '
											<table border="1" cellpadding="3">
												<thead>
											    <tr>
											      <td style="vertical-align: middle; text-align: center; width:30px;">No.</td>
											      <td style="vertical-align: middle; text-align: center; width:300px;">Menu Name</td>
											      <td style="vertical-align: middle; text-align: center; width:154px;">Price (IDR)</td>
											      <td style="vertical-align: middle; text-align: center; width:100px;">Quantity</td>
											      <td style="vertical-align: middle; text-align: center; width:170px;">Amount (IDR)</td>
											    </tr>
											  </thead>

											  <tbody>
										  ';
										}
										if ($hasil_cek_item < 1) {
											$sql_detail_item = "SELECT b.id AS id_menu, b.nama AS nama_menu, a.harga_ori AS harga_menu, 
											SUM(a.jumlah) AS sum_item, (SUM(a.jumlah)*a.harga_ori) AS amount_item FROM resto_menu a
											LEFT JOIN menu b ON b.id = a.idmenu
											WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.idresto IN 
											(SELECT id FROM resto WHERE CONCAT(YEAR(tanggal),'-',MONTH(tanggal)) = '".$_GET[date]."' 
											AND DATE_FORMAT(tanggal, '%d') = '".$baris_year[date_select]."')";
											$query_detail_item = mysql_query($sql_detail_item);
											$baris_detail_item = mysql_fetch_array($query_detail_item);
											$html=$html.'
											<tr>
												<td style="vertical-align: middle; text-align: center; width:30px;">'.$urut_menu.'</td>
												<td style="vertical-align: middle; text-align: left; width:300px;">'.$baris_detail_item[nama_menu].'</td>
												<td style="vertical-align: middle; text-align: right; width:154px;">'.number_format($baris_detail_item[harga_menu],2,",",".").'</td>
												<td style="vertical-align: middle; text-align: center; width:100px;">'.$baris_detail_item[sum_item].'</td>
												<td style="vertical-align: middle; text-align: right; width:170px;">'.number_format($baris_detail_item[amount_item],2,",",".").'</td>
											</tr>
											';
											$grand_total = $grand_total+$baris_detail_item[amount_item];
										}else{
											$sql_bayar_item = "SELECT SUM(a.jumlah) AS 'total_item', SUM(a.harga*a.jumlah) AS 'total_bayar' FROM resto_menu a 
											WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.idresto IN 
											(SELECT id FROM resto WHERE CONCAT(YEAR(tanggal),'-',MONTH(tanggal)) = '".$_GET[date]."' 
											AND DATE_FORMAT(tanggal, '%d') = '".$baris_year[date_select]."')";
											$query_bayar_item = mysql_query($sql_bayar_item);
											$hasil_bayar_item = mysql_fetch_array($query_bayar_item);
											$bayar_item = $hasil_bayar_item[total_bayar];
											$total_item = $hasil_bayar_item[total_item];

											$sql_harga_miring = "SELECT b.id AS id_menu, b.nama AS nama_menu, 
											a.harga_ori AS harga_menu, a.harga AS harga_jual FROM resto_menu a
											LEFT JOIN menu b ON b.id = a.idmenu
											WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.idresto IN 
											(SELECT id FROM resto WHERE CONCAT(YEAR(tanggal),'-',MONTH(tanggal)) = '".$_GET[date]."' 
											AND DATE_FORMAT(tanggal, '%d') = '".$baris_year[date_select]."')
											GROUP BY a.harga DESC";

											$query_nama_miring = mysql_query($sql_harga_miring);
											$baris_nama_miring = mysql_fetch_array($query_nama_miring);
											$html=$html.'
											<tr>
												<td style="vertical-align: middle; text-align: center; width:30px;" rowspan = "'.($hasil_all_item+1).'">'.$urut_menu.'</td>
												<td style="vertical-align: middle; text-align: left; width:300px;">'.$baris_nama_miring[nama_menu].'</td>
												<td style="vertical-align: middle; text-align: left; width:424px;"><i>(original price) </i>'.number_format($baris_nama_miring[harga_menu],2,",",".").'</td>
											</tr>
											';
											$query_harga_miring = mysql_query($sql_harga_miring);
											$urut_miring = 1;
											while ($baris_harga_miring = mysql_fetch_array($query_harga_miring)) {
												$sql_detail_miring = "SELECT SUM(a.jumlah) AS jumlah_item, a.harga, SUM(a.jumlah)*a.harga AS amount_miring, b.nama AS nama_menu 
												FROM resto_menu a LEFT JOIN menu b ON b.id = a.idmenu
												WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.harga = '".$baris_harga_miring[harga_jual]."' AND a.idresto IN 
												(SELECT id FROM resto WHERE CONCAT(YEAR(tanggal),'-',MONTH(tanggal)) = '".$_GET[date]."' 
												AND DATE_FORMAT(tanggal, '%d') = '".$baris_year[date_select]."')";
												$query_detail_miring = mysql_query($sql_detail_miring);
												$baris_detail_miring = mysql_fetch_array($query_detail_miring);
												$html=$html.'
													<tr>
														<td style="vertical-align: middle; text-align: left; width:300px;"> > '.$baris_detail_miring[nama_menu].' ('.$urut_miring.')'.'</td>
														<td style="vertical-align: middle; text-align: right; width:154px;">'.number_format($baris_detail_miring[harga],2,",",".").'</td>
														<td style="vertical-align: middle; text-align: center; width:100px;">'.$baris_detail_miring[jumlah_item].'</td>
														<td style="vertical-align: middle; text-align: right; width:170px;">'.number_format($baris_detail_miring[amount_miring],2,",",".").'</td>
													</tr>
												';
												$urut_miring++;
												$grand_total = $grand_total+$baris_detail_miring[amount_miring];
											}
										}
										$urut_menu++;
									}
								}
							}
						}
						$html=$html.'
						<tr style="background-color: #ddd;">
							<td style="vertical-align: middle; text-align: right; width:584px;" colspan="4">Total Amount</td>
							<td style="vertical-align: middle; text-align: right; width:170px;">'.number_format($grand_total,2,",",".").'</td>
						</tr>
						';
					}

				$html = $html.'
				</tbody>
			</table>
		';
		// end if month act
	}elseif ($_GET[act] == "yearviewrestaurant") {
		
		$html = '
			<table border="1" cellpadding="3">
				<thead>
			    <tr>
			      <td style="vertical-align: middle; text-align: center; width:30px;">No.</td>
			      <td style="vertical-align: middle; text-align: center; width:300px;">Menu Name</td>
			      <td style="vertical-align: middle; text-align: center; width:154px;">Price (IDR)</td>
			      <td style="vertical-align: middle; text-align: center; width:100px;">Quantity</td>
			      <td style="vertical-align: middle; text-align: center; width:170px;">Amount (IDR)</td>
			    </tr>
			  </thead>

			  <tbody>';
					$grand_total = 0;
	      	$hitungBaris = 0;
					$sql_year = "SELECT id AS id_resto_real, tanggal, MONTH(tanggal) AS month_select, 
					DATE_FORMAT(tanggal, '%M, %Y') AS resto_date FROM resto 
					WHERE YEAR(tanggal) = '".$_GET[date]."' 
					AND id IN (SELECT idresto FROM nota WHERE is_paid = 1 AND is_service_charge = 0) 
					AND id IN (SELECT idresto FROM resto_menu)
					GROUP BY MONTH(tanggal) ASC";
					// echo $sql_year;
					$query_year = mysql_query($sql_year);
					$count_year = mysql_num_rows($query_year);
					if ($count_year > 0) {
						$urut_menu = 1;
						$query_year = mysql_query($sql_year);
						while ($baris_year = mysql_fetch_array($query_year)) {
							$sql_month = "SELECT id AS id_resto_list, tanggal, MONTH(tanggal), 
							DATE_FORMAT(tanggal, '%M, %Y') AS resto_date FROM resto 
							WHERE YEAR(tanggal) = '".$_GET[date]."' AND MONTH(tanggal) = '".$baris_year[month_select]."'
							AND id IN (SELECT idresto FROM nota WHERE is_paid = 1 AND is_service_charge = 0) 
							AND id IN (SELECT idresto FROM resto_menu) ORDER BY MONTH(tanggal) ASC";
							$query_month = mysql_query($sql_month);
							$count_month = mysql_num_rows($query_month);
							if ($count_month > 0) {
								$html=$html.'
								<tr>
									<td colspan="5" style="background-color: #ccc; font-weight:bold;">'.$baris_year[resto_date].'</td>
								</tr>
								';
								$sql_list_item = "SELECT * FROM resto_menu a
								WHERE a.idresto IN (SELECT id FROM resto WHERE YEAR(tanggal) = '".$_GET[date]."' 
								AND MONTH(tanggal) = '".$baris_year[month_select]."') GROUP BY a.idmenu ASC";
								$query_list_item = mysql_query($sql_list_item);
								$count_list_item = mysql_num_rows($query_list_item);
								if ($count_list_item > 0) {
									$query_cek_item = mysql_query($sql_list_item);
									while ($baris_cek_item = mysql_fetch_array($query_list_item)) {
										$sql_cek_per_item = "SELECT b.id AS id_menu, b.nama AS nama_menu, 
										a.harga_ori AS harga_menu, a.harga AS harga_jual FROM resto_menu a
										LEFT JOIN menu b ON b.id = a.idmenu
										WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.idresto IN 
										(SELECT id FROM resto WHERE YEAR(tanggal) = '".$_GET[date]."' AND MONTH(tanggal) = '".$baris_year[month_select]."')";
										// echo $sql_cek_per_item."<br>";
										$query_cek_per_item = mysql_query($sql_cek_per_item);
										$hasil_cek_item = 0;
										$hasil_all_item = 0;
										while ($baris_cek_per_item = mysql_fetch_array($query_cek_per_item)) {
											$hasil_all_item++;
											if ($baris_cek_per_item['harga_menu'] != $baris_cek_per_item['harga_jual']) {
												$hasil_cek_item++;
											}
										}

										if ($hasil_cek_item == 0) {
			        				$hitungBaris++;
										}else{
			        				$hitungBaris += ($hasil_all_item+1);
										}

										$temBaris = $hasil_all_item+1;

										if($hitungBaris >= 24){
											$html = $html.'</tbody></table>';
											$pdf->writeHTMLCell(0, 0, '14', $ypage2+28, $html, 0, 1, 0, true, 'L', true);
											$pdf->AddPage();
											$hitungBaris = $temBaris;
											$html = '
											<table border="1" cellpadding="3">
												<thead>
											    <tr>
											      <td style="vertical-align: middle; text-align: center; width:30px;">No.</td>
											      <td style="vertical-align: middle; text-align: center; width:300px;">Menu Name</td>
											      <td style="vertical-align: middle; text-align: center; width:154px;">Price (IDR)</td>
											      <td style="vertical-align: middle; text-align: center; width:100px;">Quantity</td>
											      <td style="vertical-align: middle; text-align: center; width:170px;">Amount (IDR)</td>
											    </tr>
											  </thead>

											  <tbody>
										  ';
										}
										if ($hasil_cek_item < 1) {
											$sql_detail_item = "SELECT b.id AS id_menu, b.nama AS nama_menu, a.harga_ori AS harga_menu, 
											SUM(a.jumlah) AS sum_item, (SUM(a.jumlah)*a.harga_ori) AS amount_item FROM resto_menu a
											LEFT JOIN menu b ON b.id = a.idmenu
											WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.idresto IN 
											(SELECT id FROM resto WHERE YEAR(tanggal) = '".$_GET[date]."' AND MONTH(tanggal) = '".$baris_year[month_select]."')";
											$query_detail_item = mysql_query($sql_detail_item);
											$baris_detail_item = mysql_fetch_array($query_detail_item);
											$html=$html.'
											<tr>
												<td style="vertical-align: middle; text-align: center; width:30px;">'.$urut_menu.'</td>
												<td style="vertical-align: middle; text-align: left; width:300px;">'.$baris_detail_item[nama_menu].'</td>
												<td style="vertical-align: middle; text-align: right; width:154px;">'.number_format($baris_detail_item[harga_menu],2,",",".").'</td>
												<td style="vertical-align: middle; text-align: center; width:100px;">'.$baris_detail_item[sum_item].'</td>
												<td style="vertical-align: middle; text-align: right; width:170px;">'.number_format($baris_detail_item[amount_item],2,",",".").'</td>
											</tr>
											';
											$grand_total = $grand_total+$baris_detail_item[amount_item];
										}else{
											$sql_bayar_item = "SELECT SUM(a.jumlah) AS 'total_item', SUM(a.harga*a.jumlah) AS 'total_bayar' FROM resto_menu a 
											WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.idresto IN 
											(SELECT id FROM resto WHERE YEAR(tanggal) = '".$_GET[date]."' AND MONTH(tanggal) = '".$baris_year[month_select]."')";
											$query_bayar_item = mysql_query($sql_bayar_item);
											$hasil_bayar_item = mysql_fetch_array($query_bayar_item);
											$bayar_item = $hasil_bayar_item[total_bayar];
											$total_item = $hasil_bayar_item[total_item];

											$sql_harga_miring = "SELECT b.id AS id_menu, b.nama AS nama_menu, 
											a.harga_ori AS harga_menu, a.harga AS harga_jual FROM resto_menu a
											LEFT JOIN menu b ON b.id = a.idmenu
											WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.idresto IN 
											(SELECT id FROM resto WHERE YEAR(tanggal) = '".$_GET[date]."' AND MONTH(tanggal) = '".$baris_year[month_select]."')
											GROUP BY a.harga DESC";

											// echo $sql_harga_miring."<br>";

											$query_nama_miring = mysql_query($sql_harga_miring);
											$baris_nama_miring = mysql_fetch_array($query_nama_miring);
											$html=$html.'
											<tr>
												<td style="vertical-align: middle; text-align: center; width:30px;" rowspan = "'.($hasil_all_item+1).'">'.$urut_menu.'</td>
												<td style="vertical-align: middle; text-align: left; width:300px;">'.$baris_nama_miring[nama_menu].'</td>
												<td style="vertical-align: middle; text-align: left; width:424px;"><i>(original price) </i>'.number_format($baris_nama_miring[harga_menu],2,",",".").'</td>
											</tr>
											';
											$query_harga_miring = mysql_query($sql_harga_miring);
											$urut_miring = 1;
											while ($baris_harga_miring = mysql_fetch_array($query_harga_miring)) {
												$sql_detail_miring = "SELECT SUM(a.jumlah) AS jumlah_item, a.harga, SUM(a.jumlah)*a.harga AS amount_miring, b.nama AS nama_menu 
												FROM resto_menu a LEFT JOIN menu b ON b.id = a.idmenu
												WHERE a.idmenu = ".$baris_cek_item[idmenu]." AND a.harga = '".$baris_harga_miring[harga_jual]."' AND a.idresto IN 
												(SELECT id FROM resto WHERE YEAR(tanggal) = '".$_GET[date]."' AND MONTH(tanggal) = '".$baris_year[month_select]."')";
												$query_detail_miring = mysql_query($sql_detail_miring);
												$baris_detail_miring = mysql_fetch_array($query_detail_miring);
												$html=$html.'
													<tr>
														<td style="vertical-align: middle; text-align: left; width:300px;"> > '.$baris_detail_miring[nama_menu].' ('.$urut_miring.')'.'</td>
														<td style="vertical-align: middle; text-align: right; width:154px;">'.number_format($baris_detail_miring[harga],2,",",".").'</td>
														<td style="vertical-align: middle; text-align: center; width:100px;">'.$baris_detail_miring[jumlah_item].'</td>
														<td style="vertical-align: middle; text-align: right; width:170px;">'.number_format($baris_detail_miring[amount_miring],2,",",".").'</td>
													</tr>
												';
												$urut_miring++;
												$grand_total = $grand_total+$baris_detail_miring[amount_miring];
											}
										}
										$urut_menu++;
									}
								}
							}
						}
						$html=$html.'
						<tr style="background-color: #ddd; font-wight: bold;">
							<td style="vertical-align: middle; text-align: right; width:584px;" colspan="4">Total Amount</td>
							<td style="vertical-align: middle; text-align: right; width:170px;">'.number_format($grand_total,2,",",".").'</td>
						</tr>
						';
					}

				$html = $html.'
				</tbody>
			</table>
		';
		//---end if year act
	} 

$pdf->writeHTMLCell(0, 0, '14', $ypage2+28, $html, 0, 1, 0, true, 'L', true);

//Close and output PDF document
$pdf->Output('Lembongan-Island-'.$_GET[act].'_'.$_GET[date].'.pdf', 'I');

?>